package project.active;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import models.util.UtilInitLang;

import project.adapter.Projectdetail_info_adapter_tc;
import project.adapter.Projectdetail_listerror_adapter_tc;
import project.dao.pr_projectDAO;
import project.model.PrComposition;
import project.model.PrProject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import approve.action.R;

public class Projectdetail_info_tc extends Activity {

	TextView nameproject,startdate,manager,status,description,lbproInfo,lbproname,lbstartdate,lbmanager,lbstatus,lbdescription,lbmember,lbtester,lbcoder;
	Button btadderror;
	ListView tester,coder;
	PrProject pro=new PrProject();
	pr_projectDAO pr=new pr_projectDAO();
	String lang = "EN",database="admin";
	Bundle language;
	
	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}
	
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.projectdetail_info_tc);
		
		language=getIntent().getExtras().getBundle(getLang());
		
		Intent i=this.getIntent();
		pro=(PrProject)i.getSerializableExtra("project");
		
		temp(pro);
		
		Projectdetail_info_adapter_tc adapter1 = new Projectdetail_info_adapter_tc(this, loadAllTester());
		tester.setAdapter(adapter1);
		Projectdetail_info_adapter_tc adapter2 = new Projectdetail_info_adapter_tc(this, loadAllCoder());
		coder.setAdapter(adapter2);
		
	}

	
	public List<PrComposition> loadAllTester(){
		List<PrComposition> item=new ArrayList<PrComposition>();
		item=pr.getLoadAllTesterDAO_tc(getDatabase(),pro.getIdProject(),0);
		return item;
	}
	public List<PrComposition> loadAllCoder(){
		List<PrComposition> item=new ArrayList<PrComposition>();
		item=pr.getLoadAllTesterDAO_tc(getDatabase(),pro.getIdProject(),1);
		return item;
	}
	
	public void temp(PrProject pro){
		nameproject=(TextView)findViewById(R.id.txtProjectName);
		startdate=(TextView)findViewById(R.id.txtstatusdate);
		manager=(TextView)findViewById(R.id.txtmanager);
		tester=(ListView)findViewById(R.id.listtester);
		coder=(ListView)findViewById(R.id.listcoder);
		status=(TextView)findViewById(R.id.txtstatus);
		description=(TextView)findViewById(R.id.txtdescription);
		
		nameproject.setText(pro.getNameProject());
		SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd");
//		startdate.setText(format1.format(loadDateStart(pro.getIdProject())));
		startdate.setText(format1.format(pro.getDateStart()));
		
//		manager.setText(loadManagerName(pro.getIdManager()));
		manager.setText(pro.getManager());
		String st=null;
		if(pro.getStatus()==0)
			st="Uncomplete";
		else
			st="Completed";
		status.setText(st);
		description.setText(pro.getDescription());
		
		lbproInfo=(TextView)findViewById(R.id.lbproInfo);
		lbproname=(TextView)findViewById(R.id.lbproname);
		lbstartdate=(TextView)findViewById(R.id.lbstartdate);
		lbmanager=(TextView)findViewById(R.id.lbmanager);
		lbstatus=(TextView)findViewById(R.id.lbstatus);
		lbdescription=(TextView)findViewById(R.id.lbdescription);
		lbmember=(TextView)findViewById(R.id.lbmember);
		lbtester=(TextView)findViewById(R.id.lbtester);
		lbcoder=(TextView)findViewById(R.id.lbcoder);
		
		lbproInfo.setText(language.getString("project_info"));
		lbproname.setText(language.getString("ac_SUProjectName"));
		lbstartdate.setText(language.getString("start_date"));
		lbmanager.setText(language.getString("ac_Manager"));
		lbstatus.setText(language.getString("ac_Status"));
		lbdescription.setText(language.getString("Description"));
		lbmember.setText(language.getString("lstmember"));
		lbtester.setText(language.getString("tester_team"));
		lbcoder.setText(language.getString("coder_team"));
	}
	
//	private String loadManagerName(String idManager){
//		String name=null;
//		name=pr.getLoadManagerNameByID_tc(getDatabase(),idManager);
//		return name;
//	}
//	
//	private Date loadDateStart(String idManager){
//		Date name=null;
//		name=pr.getLoadDateStartByID_tc(getDatabase(),idManager);
//		return name;
//	}
	
//	public void loadClassAddError(){
//		Intent in=new Intent(this,Projectdetail_error_tc.class);
//		in.putExtra("project", pro);
//		startActivity(in);
//	}
}
